using System.Collections.Generic;
using System.Linq;

namespace ProjectEuler.Core
{
    public class Problem28 : IProjectEulerProblem
    {
        private const int SIZE = 1001*1001;

        public int Number
        {
            get { return 28; }
        }

        public string Description
        {
            get
            {
                return "What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral?";
            }
        }

        public string Answer
        {
            get
            {
                return SumOfDiagonals().ToString();
            }
        }

        protected long SumOfDiagonals()
        {
            var sum = 1;
            IList<int> nums = Enumerable.Range(1,SIZE).ToList();
            var index = 0;
            var indexjump = 2;
            while ((index + indexjump) < SIZE)
            {
                for (int dummy = 0; dummy < 4; dummy++)
                {
                    sum += nums[index + indexjump];
                    index += indexjump;
                }
                indexjump += 2;
            }
            return sum;
        }
    }
}